@{
    Layout = null;
}
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>节假日设置</title>
    <link href="~/scripts/layui-v2.5.6/layui/css/layui.css" rel="stylesheet" />
    <script src="~/scripts/jquery-3.4.1.min.js"></script>
    <script src="~/scripts/layui-v2.5.6/layui/layui.js"></script>
    <style>
        body {
            margin: 0;
            padding: 0;
            background: #fff;
            font-family: 'Microsoft YaHei', sans-serif;
            font-size: 14px;
        }
        .form-container {
            padding: 20px;
        }
        .form-header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 20px;
            padding-bottom: 10px;
            border-bottom: 1px solid #e6e6e6;
        }
        .form-title {
            font-size: 16px;
            font-weight: 500;
            color: #333;
        }
        .close-btn {
            width: 24px;
            height: 24px;
            line-height: 22px;
            text-align: center;
            background: #f5f5f5;
            border: 1px solid #ddd;
            border-radius: 2px;
            cursor: pointer;
            color: #666;
        }
        .close-btn:hover {
            background: #e6e6e6;
        }
        .layui-form-item {
            margin-bottom: 20px;
        }
        .layui-form-label {
            width: 80px;
            padding: 9px 15px 9px 0;
            text-align: right;
            font-size: 14px;
        }
        .layui-input-block {
            margin-left: 90px;
        }
        .required {
            color: #ff5722;
            margin-right: 2px;
        }
        .form-buttons {
            text-align: center;
            padding: 20px 0;
            border-top: 1px solid #e6e6e6;
            margin-top: 20px;
        }
        .layui-btn {
            padding: 0 25px;
            height: 38px;
            line-height: 38px;
        }
        .type-radio {
            margin-right: 20px;
        }
    </style>
</head>
<body>
    <div class="form-container">
        <div class="form-header">
            <div class="form-title">节假日设置</div>
            <div class="close-btn" id="closeBtn">×</div>
        </div>
        
        <form class="layui-form" id="holidayForm" lay-filter="holidayForm">
            <input type="hidden" name="id" id="recordId">
            
            <div class="layui-form-item">
                <label class="layui-form-label"><span class="required">*</span>日期</label>
                <div class="layui-input-block">
                    <input type="text" name="HolidaysTime" lay-verify="required" placeholder="请选择日期" class="layui-input" id="holidayDate">
                </div>
            </div>
            
            <div class="layui-form-item">
                <label class="layui-form-label"><span class="required">*</span>类型</label>
                <div class="layui-input-block">
                    <input type="radio" name="HolidaysType" value="假" title="假" class="type-radio" checked>
                    <input type="radio" name="HolidaysType" value="班" title="班" class="type-radio">
                </div>
            </div>
            
            <div class="form-buttons">
                <button class="layui-btn" lay-submit lay-filter="saveBtn">确定</button>
                <button type="button" class="layui-btn layui-btn-primary" id="cancelBtn">取消</button>
            </div>
        </form>
    </div>

    <script>
        layui.use(['form', 'laydate', 'layer'], function() {
            var form = layui.form;
            var laydate = layui.laydate;
            var layer = layui.layer;
            
            // 获取URL参数
            var urlParams = new URLSearchParams(window.location.search);
            var action = urlParams.get('action');
            var id = urlParams.get('id');
            var date = urlParams.get('date');
            var holidayType = urlParams.get('holidayType');
            
            console.log('表单参数:', { action, id, date, holidayType });
            
            // 如果有ID参数，设置到隐藏字段
            if (id) {
                $('#recordId').val(id);
                console.log('设置ID到隐藏字段:', id);
            }
            
            // 如果有日期参数，自动填充
            if (date) {
                $('input[name="HolidaysTime"]').val(date);
            }
            
            // 如果有节假日类型参数，自动选中
            if (holidayType) {
                if (holidayType === '班' || holidayType === 'workday') {
                    $('input[name="HolidaysType"][value="班"]').prop('checked', true);
                } else {
                    $('input[name="HolidaysType"][value="假"]').prop('checked', true);
                }
                form.render('radio'); // 重新渲染单选框
            }
            
            // 如果是编辑模式，更新标题
            if (action === 'edit') {
                document.querySelector('.form-title').textContent = '修改节假日设置';
            }
            
            // 日期选择器
            laydate.render({
                elem: '#holidayDate',
                type: 'date',
                format: 'yyyy-MM-dd'
            });
            
            // 表单提交
            form.on('submit(saveBtn)', function(data) {
                var formData = data.field;
                
                // 数据验证
                if (!formData.HolidaysTime) {
                    layer.msg('请选择日期', {icon: 2});
                    return false;
                }
                if (!formData.HolidaysType) {
                    layer.msg('请选择类型', {icon: 2});
                    return false;
                }
                
                console.log('提交数据:', formData);
                console.log('日期值:', formData.HolidaysTime);
                console.log('日期类型:', typeof formData.HolidaysTime);
                console.log('ID值:', formData.id);
                console.log('动作:', action);
                
                // 提交到服务器
                var url = action === 'edit' ? '/HolidaysSet/Update' : '/HolidaysSet/Create';
                
                // 显示加载提示
                var loadIndex = layer.load(1, {shade: [0.1,'#000']});
                
                $.post(url, formData)
                    .done(function(result) {
                        layer.close(loadIndex);
                        console.log('服务器响应:', result);
                        if (result.success || result.Success) {
                            layer.msg(action === 'edit' ? '修改成功' : '新增成功', {icon: 1}, function() {
                                // 通知父窗口刷新数据
                                if (parent && parent.refreshCalendar) {
                                    parent.refreshCalendar();
                                }
                                // 关闭当前窗口
                                var index = parent.layer.getFrameIndex(window.name);
                                parent.layer.close(index);
                            });
                        } else {
                            console.error('操作失败:', result);
                            layer.msg(result.message || result.Message || '操作失败', {icon: 2});
                        }
                    })
                    .fail(function(xhr, status, error) {
                        layer.close(loadIndex);
                        console.error('请求失败:', xhr.responseText);
                        layer.msg('网络错误，请稍后重试', {icon: 2});
                    });
                
                return false;
            });
            
            // 取消按钮和关闭按钮
            $('#cancelBtn, #closeBtn').click(function() {
                var index = parent.layer.getFrameIndex(window.name);
                parent.layer.close(index);
            });
        });
    </script>
</body>
</html> 